﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HidesaburoDotNET.Core.Detecctors
{
    public class ChurenDetector : YakuDetector
    {
        public override Yaku CheckYaku(AgariTehai agariTehai)
        {
            if (!agariTehai.Menzen)
            {
                return new Yaku();
            }
            HaiType a = HaiType.None;
            foreach (Hai h in agariTehai.Hai)
            {
                if (h.Type != HaiType.Jihai)
                {
                    if (a == HaiType.None)
                    {
                        a = h.Type;
                    }
                    else if (a != h.Type)
                    {
                        return new Yaku();
                    }

                }
                else
                {
                    return new Yaku();
                }
            }

            int i = 0;
            int b0 = 0;
            int[] b = new int[9];
            for (; i < agariTehai.Hai.Count; i++)
            {
                b0 = agariTehai.Hai[i].Number - 1;
                b[b0]++;
            }

            bool allMoreThan1 = true;
            for (int j = 0; j < b.Length; j++)
            {
                allMoreThan1 &= (b[j] > 0);
            }

            if (allMoreThan1 && b[0] > 2 && b[8] > 2)
            {
                return new Yaku(13, "チューレンホウトウ");
            }
            else
            {
                return new Yaku();
            }
        }
    }
}
